import * as THREE from 'three'
export class Cone{
    constructor(scene,time,top,height){
        this.scene = scene;
        this.color = '#fab73f';
        this.top =  top;
        this.height = height;
        this.createCone()
    }

    createCone(){

        const geometry = new THREE.ConeGeometry(
            15,
            30,
            4,
        )
        const material = new THREE.ShaderMaterial({
            uniforms:{
                u_color:{
                    value: new THREE.Color(this.color)
                },
                u_height: this.height,
                u_top: this.top
            },
            transparent: true,
            side:THREE.DoubleSide,
            vertexShader:`
                uniform float u_top;
                uniform float u_height;
                void main(){
                    float f_angle = u_height/10.0;
                    float new_x = position.x *cos(f_angle) - position.z *sin(f_angle);
                    float new_y = position.y;
                    float new_z = position.z *cos(f_angle) - position.x *sin(f_angle);
                    
                    vec4 v_position = vec4(new_x,new_y,new_z,1.0);
                    gl_Position = projectionMatrix * modelViewMatrix * v_position;
                }
            `,
            fragmentShader:`
                uniform vec3 u_color;
                uniform float u_opacity;
                void main(){
                    gl_FragColor = vec4(u_color,0.6);
                }
            `
        })

        const mesh = new THREE.Mesh(geometry,material)
        mesh.position.set(0,200,0)
        this.scene.add(mesh)
    }
}